<template>
<!--  本意不想这么写 赶时间 只有复制粘贴 后面的小伙 加油 -->
  <a-modal title="补充信息" :visible="visible" @cancel="cancel" width="700px">
    <a-form-model ref="ruleForm2" :model="form3" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }" v-if="!isA">
      <a-row :gutter="24">
        <a-col :md="12" :sm="12">
          <a-form-model-item label="外部报审是否通过：">
            <a-radio-group v-model="form3.auditPass">
              <a-radio :value="1">是</a-radio>
              <a-radio :value="0">否</a-radio>
            </a-radio-group>
          </a-form-model-item>
        </a-col>
        <a-col :md="12" :sm="12" v-if="form3.auditPass!==0">
          <a-form-model-item label="外部报审通过时间：" prop="startTime" class="requiredFormItem">
            <a-date-picker v-model="form3.auditTime" placeholder="请选择" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
          </a-form-model-item>
        </a-col>
        <a-col :span="24" v-if="form3.auditPass!==0">
          <a-form-model-item label="外部报审表：" prop="startTime">
            <b-upload uploadType="single" business-code="LCM16"
                      :file-list.sync="form3.fileInfoList"></b-upload>
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
    <div v-else>
      <titleName ref="box" title="一次报审外部信息" />
      <a-form-model ref="ruleForm" :model="form" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-model-item label="外部报审是否通过：">
              <a-radio-group v-model="form.auditPass">
                <a-radio :value="1">是</a-radio>
                <a-radio :value="0">否</a-radio>
              </a-radio-group>
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12" v-if="form.auditPass!==0">
            <a-form-model-item label="一次外部报审通过时间：" prop="startTime" class="requiredFormItem">
              <a-date-picker v-model="form.auditTime" placeholder="请选择" format="YYYY-MM-DD" value-format="YYYY-MM-DD"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24" v-if="form.auditPass!==0">
            <a-form-model-item label="外部报审表：" prop="startTime">
            <b-upload uploadType="single" business-code="LCM16"
                      :file-list.sync="form.fileInfoList"></b-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      <titleName ref="box" title="二次报审外部信息" />
      <a-form-model ref="ruleForm2" :model="form2" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-model-item label="外部报审是否通过：">
              <a-radio-group v-model="form2.auditPass">
                <a-radio :value="1">是</a-radio>
                <a-radio :value="0">否</a-radio>
              </a-radio-group>
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12" v-if="form2.auditPass!==0">
            <a-form-model-item label="二次外部报审通过时间：" prop="startTime" class="requiredFormItem">
                <a-date-picker v-model="form2.auditTime" placeholder="请选择" format="YYYY-MM-DD" value-format="YYYY-MM-DD"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24" v-if="form2.auditPass!==0">
            <a-form-model-item label="外部报审表：" prop="startTime">
            <b-upload uploadType="single" business-code="LCM16"
                      :file-list.sync="form2.fileInfoList"></b-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </div>
    <template slot="footer">
      <a-button @click="cancel"> 取消 </a-button>
      <a-button type="primary" @click="handleOk" :loading="loading"> 确定 </a-button>
    </template>
  </a-modal>
</template>
  <script>
    import { technicalSupplement } from "@/api/technology"
export default {
  props: {
    // 显隐控件
    visible: {
      type: Boolean,
      default() {
        return false
      }
    },
    row: {
      type: Object,
      default() {
        return {  };
      }
    }
  },
  data() {
    return {
      form: {
        type: 1,
        auditPass: null,
        auditTime: null,
        fileInfoList: []
      },
      form2: {
        type: 2,
        auditPass: null,
        auditTime: null,
        fileInfoList: []
      },
      form3: {
        type: 0,
        auditPass: null,
        auditTime: null,
        fileInfoList: []
      },
      loading: false
    }
  },
  computed: {
    isA() {
      return this.row.schemeCategory === 'A'
    }
  },
  methods: {
    cancel() {
      this.$emit('cancel', false)
      this.$refs.ruleForm.resetFields();
      this.$refs.ruleForm2.resetFields();
    },
    handleOk() {
      if(this.isA) {
        if(this.form.auditPass == 0 || this.form2.auditPass == 0) {

        } else  {
          if(this.form.auditPass === null && this.form2.auditPass === null) {
            this.$message.warning('请选择外部报审是否通过')
            return
          }
          if(this.form.auditPass==1&&!this.form.auditTime) {
            this.$message.warning('请选择外部报审通过时间')
            return
          }
          if(this.form.auditPass==1&&!this.form.fileInfoList?.length) {
            this.$message.warning('请上传外部报审表')
            return
          }
          if(this.form.auditPass!=1&&this.form2.auditPass === null) {
            this.$message.warning('请选择外部报审是否通过')
            return
          }
          if(this.form2.auditPass==1&&!this.form2.auditTime) {
            this.$message.warning('请选择二次外部报审通过时间')
            return
          }
          if(this.form2.auditPass==1&&!this.form2.fileInfoList?.length) {
            this.$message.warning('请上传外部报审表')
            return
          }
        }

      } else {
        if(this.form3.auditPass === null) {
          this.$message.warning('请选择外部报审是否通过')
          return
        }
        if(this.form3.auditPass==1&&!this.form3.auditTime) {
          this.$message.warning('请选择外部报审通过时间')
          return
        }
        if(this.form3.auditPass==1&&!this.form3.fileInfoList?.length) {
          this.$message.warning('请上传外部报审表')
          return
        }
      }
      let data = []
      if(this.isA) {
        this.form.constructionId = this.row.id
        data.push({...this.form})
        this.form2.constructionId = this.row.id
        data.push({...this.form2})
      }else {
        this.form3.constructionId = this.row.id
        data.push({...this.form3})
      }
      let arr = []
      data.forEach(item=>{
        item.fileInfoIds = item.fileInfoList
        item.versionNum = this.row.versionNumber
        delete item.fileInfoList
        if(item.auditPass !== null) {
          arr.push(item)
        }
      })

      this.loading = true
      technicalSupplement(arr).then(res=>{
        this.loading = false
        this.$emit('handleSuccess')
      }).catch(()=>{
        this.loading = false
      })
    },
  }
}
</script>